/*
 * pointset.h
 *
 *  Created on: Mar 1, 2011
 *      Author: tqlong
 */

#ifndef POINTSET_H_
#define POINTSET_H_

#include <cassert>

template <typename T>
class Point : public T
{
public:
  typedef T                   vec_type;
public:
  Point(const vec_type& x) : T(x) {}
  Point(int dim = 1) : T(dim) {}

  void save(const std::string& fname);
  void save(std::ostream& f);
  bool load(const std::string& fname);
  bool load(std::istream& f);
};

template <typename T>
class PointSet : public std::vector<Point<T> >
{
protected:
  int dim_;
public:
  typedef Point<T>              vec_type;
  typedef std::vector<vec_type> set_type;

  void save(const std::string& fname);
  void save(std::ostream& f);
  void load(const std::string& fname);
  void load(std::istream& f);
  void generate(int n, int d, double noise);

  const int dim() const { return dim_; }
  const int n() const { return this->size(); }
  const vec_type& x(int i) const { assert((unsigned int)i < this->size()); return *(this->begin()+i); }
};

#include "pointset_impl.h"

#endif /* POINTSET_H_ */
